# Use Python 3.12 as base image with automatic architecture detection
ARG TARGETPLATFORM=linux/amd64

# Select base image based on target platform
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/python:3.12-slim AS x86_image
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/library/python:3.12-slim-linuxarm64 AS arm64_image

FROM x86_image AS linux-amd64
FROM arm64_image AS linux-arm64

FROM ${TARGETPLATFORM}

# Set working directory
WORKDIR /app


# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONIOENCODING=utf-8 \
    APP_HOST=0.0.0.0 \
    APP_PORT=5000 \
    APP_DEBUG=false \
    DOCKER_CONTAINER=true

# 替换为阿里云镜像源（Debian/Ubuntu 通用）
RUN cp -a /etc/apt/sources.list.d /etc/apt/sources.list.d.bak
RUN sed -i 's/deb.debian.org/mirrors.huaweicloud.com/g' /etc/apt/sources.list.d/debian.sources

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    libc6-dev \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements file
COPY requirements.txt .



# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/ && \
    pip install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ 

# Copy application code
COPY . .

# Ensure entrypoint script is executable
RUN chmod +x entrypoint.sh

# Create directories
RUN mkdir -p /app/uploads /app/results /app/logs && \
    chmod -R 755 /app/uploads /app/results /app/logs

# Expose port
EXPOSE 5000

# Set the entrypoint script
ENTRYPOINT ["/app/entrypoint.sh"] 

